"""用户状态路由"""
from fastapi import APIRouter
from app.services.user_onboarding_service import user_onboarding_service

router = APIRouter()


@router.get("/user-status/{user_id}")
async def get_user_status(user_id: str):
    """获取用户状态"""
    try:
        status = user_onboarding_service.get_user_status(user_id)
        return status
    except Exception as e:
        import traceback
        traceback.print_exc()
        # 如果出错，返回默认状态，不阻塞请求
        return {
            "user_id": user_id,
            "has_completed_test": False,
            "has_plan": False,
            "plan_id": None,
            "current_stage": "first_visit",
            "error": str(e)
        }


@router.get("/user-status/{user_id}/test-result")
async def get_test_result(user_id: str):
    """获取测试结果"""
    test_result = user_onboarding_service.get_test_result(user_id)
    if not test_result:
        return {"error": "未找到测试结果"}
    return test_result

